let mongoose = require('./index');
let { Schema, Model } = mongoose    

// 创建交易记录Schema
const TransactionSchema = new Schema({
  id: {
    type: String,
    required: true,
    unique: true
  },
  from: {
    type: String,
    required: true
  },
  to: {
    type: String,
    required: true
  },
  amount: {
    type: Number,
    required: true
  },
  timestamp: {
    type: String,
    required: true
  },
  status: {
    type: String,
    required: true,
    enum: ['pending', 'completed', 'failed']
  },
  hash: {
    type: String,
    required: true
  }
});

// 创建用户余额Schema
const BalanceSchema = new Schema({
  address: {
    type: String,
    required: true,
    unique: true
  },
  balance: {
    type: Number,
    required: true,
    default: 1000 // 默认初始余额为1000元
  }
});

// 创建模型
const Transaction = mongoose.model('Transaction', TransactionSchema);
const Balance = mongoose.model('Balance', BalanceSchema);

// 导出模型
exports.Transaction = Transaction;
exports.Balance = Balance;
